<template>
  <div>
    <div class="search">
      <input
        type="text"
        placeholder=" 请输入要查询的菜品名称"
        v-model="foodName"
      />
      <button @click="search(foodName)">查询</button>
    </div>
    <div class="list">
      <div
        class="item"
        @click="add(v.foodId)"
        v-for="v in item"
        :key="v.foodId"
      >
        <div class="img">
          <img :src="v.foodPic" />
        </div>
        <div class="xiangqing">
          <p class="name">{{ v.foodName }}</p>
          <p class="guige">{{ v.foodUnit }}</p>
          <p class="price">{{ v.foodMoney }}</p>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { findAll, findByLike } from "@/apis/liwenjing/diancan.js";
export default {
  data() {
    return {
      item: [],
      foodName: "",
      table: this.$route.query.zhuowei,
      // foodNum: [],
    };
  },
  methods: {
    // 失焦  模糊查询全部菜品
    search(foodName) {
      findByLike(foodName).then((ok) => {
        console.log(ok);
      });
    },
    // 点击添加菜品
    add(foodId) {
  
      this.$store.commit("add",foodId)
      // this.$store.commit("addcount")

    },
  },
  mounted() {
    console.log(this.table);
    // 跳转到点餐页面 自动渲染全部菜品
    findAll().then((ok) => {
      console.log(ok);
      this.item = ok.data.data;
      this.$store.commit("AMOUNTED_ADD",ok.data.data)
    });

  },

};
</script>

<style scoped>
* {
  padding: 0;
  margin: 0;
}

.search {
  height: 36px;
  width: 1000px;
  margin: auto;
  /* background-color: #bab6b6; */
}
.search input {
  margin: 5px;
  height: 28px;
  width: 1000px;
  border-color: #bab6b6;
  border-radius: 5px;
}

.list {
  width: 1200px;
  height: auto;
  box-sizing: border-box;
  display: flex;
  flex-wrap: wrap;
  margin: 5px auto;
  border-radius: 8px;
}
.list .item {
  width: 280px;
  height: 120px;
  border: 1px solid #bab6b6;
  border-radius: 6px;
  background-color: rgb(255, 207, 191);
  margin: 10px 10px;
  display: flex;
  justify-content: space-around;
  box-sizing: border-box;
}
img {
  width: 100px;
  height: 90px;
  border-radius: 10px;
  margin: 14px 0;
}
.item .xiangqing {
  width: 100px;
  height: 100px;
  line-height: 28px;
  margin: 14px 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

.xiangqing .price {
  align-self: flex-end;
}
.search {
  display: flex;
}
</style>